/*讨论活动 交流圈js*/
$(function(){
	var contentHTML="";
	var imgListHTML="";
	var datas=[];
	var datas1=[];
	var curData={};
	ym.ajax({
		url: "/ymUserInfrom/exchange",
		success: function(data){
			var newData=data.obj[0].list1;
			if (newData){
		   	datas=newData;
		   	contentHTML="";
		   	
			 for (var i = 0; i < newData.length; i++) {
			 	
			 	if(newData[i].attachmentUrl===undefined){
			 		contentHTML+="<li class='content-tab' curIndex='"+newData[i].exchangeId+"'>"+
			 				 "<div style='display:flex;display:-webkit-flex;align-items:center;-webkit-align-items:center;overflow:hidden'>"+
		          		 	 "<div class='tab-desc-text' style='border:none'>"+newData[i].ecchangeMessage+"</div>"+
		          		 	 
		          		 	 "</div>"+
		          		 	 "<div class='tab-foot disflex'>"+
		          		 	 "<p style='width:85%'>"+newData[i].createTime+"</p>"+
		          		 	  "<p style='width:15%'><img src='../img/pinglun.png'><i class='font12'>回复</i></p>"+
		          		 	 "</div>"+
		          		 	 "</li>";
			 	}else{
			 		var imgList=newData[i].attachmentUrl.split(',');
			 		contentHTML+="<li class='content-tab' curIndex='"+newData[i].exchangeId+"'>"+
			 				 "<div style='display:flex;display:-webkit-flex;align-items:center;-webkit-align-items:center;overflow:hidden'>"+
			 				 	"<div class='tab-desc-text' style='border:none'>"+newData[i].ecchangeMessage+"</div>"+
		          		 	  "</div>"+
		          		 	  "<div style='width:25%;height:100px;display:block;'> <img style='width:100%;max-height:100px' src='"+imgList[0]+"'></div>"+
		          		 	  "<div class='tab-foot disflex'>"+
		          		 	 "<p style='width:85%'>"+newData[i].createTime+"</p>"+
		          		 	 "<p style='width:15%'><img src='../img/pinglun.png'><i class='font12'>回复</i></p>"+
		          		 	 "</div>"+
		          		 	 "</li>";	
			 	}
			 }
			 
		   }else{
		   		contentHTML = '<li class="am-text-center"><img style="height:150px" src="../img/no.jpg"></li>';
		   }
		   $('#activesTab').html(contentHTML)
		}
	});
	/*问医生 查看*/
	function getAskDoctor(){
		ym.ajax({
			url: "/Answer/queryYmAnswerListAnswerByUserId",
			param:{
				type:'2',
			},
			success: function (data) {
				console.log(data);
				var newData=data.obj;
			   if (data.res == 1){
			   		if(data.obj.length >0){
					   	datas1=newData;
					   	contentHTML="";
						for (var i = 0; i <newData.length; i++){
							var zhi = newData[i].ymAnswerVO.ymAttachments;
							contentHTML+="<li class='content-tab' curIndex='"+newData[i].ymAnswerVO.answerId+"'>"
				 			contentHTML+= "<div style='display:flex;display:-webkit-flex;align-items:center;-webkit-align-items:center;overflow:hidden'>"
				 			contentHTML+="<div class='tab-desc-text' style='border:none'>"+newData[i].ymAnswerVO.answerDes+"</div>"
			          		contentHTML+="</div>"
			          		if(newData[i].ymAnswerVO.ymAttachments.length !=0){
			          			contentHTML+= "<div style='width:100%;display:block;'>"
			          			for(var n=0;n<newData[i].ymAnswerVO.ymAttachments.length;n++){
			          				var list = newData[i].ymAnswerVO.ymAttachments[n].attachmentUrl;
			          				contentHTML+= "<img style='width:29%;height:100px;margin-right:1rem' src='"+newData[i].ymAnswerVO.ymAttachments[n].attachmentUrl+"'>"
			          			}
			          			contentHTML+= "</div>"
			          		}
			          		//contentHTML+= "<div style='width:25%;height:100px;display:block;'> <img style='width:100%' src='"+imgList+"'></div>"
			          		contentHTML+= "<div class='tab-foot disflex'>"
			          		contentHTML+= "<p style='width:85%'>"+newData[i].ymAnswerVO.createTimeString+"</p>"
			          		contentHTML+="<p style='width:15%'><img src='../img/pinglun.png'><i class='font12'>回复</i></p>"
			          		contentHTML+= "</div>"
			          		contentHTML+= "</li>";	
						}
					}else{
						contentHTML = '<li class="am-text-center"><img style="height:150px" src="../img/no.jpg"></li>';
					}
					$('#askDoctorTab').html(contentHTML)
				}else{
					console.log("数据获取失败!")
			   }
			 }
		});
	}
	getAskDoctor();
	window.setTimeout(function(){
		/*查看交流圈的详情*/
		$('#activesTab .content-tab').click(function(){
			var curIndex=$(this).attr('curIndex');
			
			for (var i = 0; i < datas.length; i++) {
				if(datas[i].exchangeId==curIndex){
					window.location.href="topic.html?exchangeId="+datas[i].exchangeId+"&userid="+datas[i].userId+"&a=0";
				}
			}
		})
		/*查看问医生的详情*/
		$('#askDoctorTab .content-tab').click(function(){
			var curIndex=$(this).attr('curIndex');
			console.log($(this))
			for (var i = 0; i < datas1.length; i++) {
				if(datas1[i].ymAnswerVO.answerId==curIndex){
					curData=datas1[i];
					ym.ajax({
						url: "/Answer/queryYmAnswerListDetail",
						param:{
							typeId:datas1[i].ymAnswerVO.typeId,
							answerId:datas1[i].ymAnswerVO.answerId,
							praiseType:4,
							parentAnswerId:datas1[i].ymAnswerVO.answerId
						},
						success: function (data) {
						  sessionStorage.setItem('articleXq',JSON.stringify(data.obj));
						  window.location.href='../html/problemXq.html?a=0';
						},
						error:function(){
							sessionStorage.clear();
						}
					});
					
				}
			}
		})
	},1500)
})